/**
 * Created by Administrator on 2016/5/11.
 */
var express = require('express');
var app = express();

var deck1 = {
    card1: 'd1_card1',
    card2: 'd1_card2'
};

var deck2 = {
    card1: 'd2_card1',
    card2: 'd2_card2'
};

app.param('deckId', function (req, res, next) {
    req.deckId = req.params.deckId.toLowerCase();
    next();
})

app.get('/deck1/:deckId', function (req, res) {
    var cardName = deck1[req.deckId];
    if(cardName){
        res.json(cardName);
    }else{
        res.status(404).json('No card found for '+req.params.deckId);
    }
});

app.get('/deck2/:deckId', function (req, res) {
    var cardName = deck2[req.deckId];
    if(cardName) {
        res.json(cardName);
    } else {
        res.status(404).json('No card found for '+req.params.deckId);
    }
});

app.listen(8080);